package com.baohua.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.baohua.dao.BaseDao;
import com.baohua.dao.MaterielInformationDao;
import com.baohua.model.MaterielInformation;

@Repository("materielInfomationDao")
public class MaterielInfomationDaoImpl extends BaseDao implements MaterielInformationDao {

	@Override
	public List<MaterielInformation> getMaterielInfomation(String sql,
			int page, int pagesize) {
		return this.getSession().createQuery(sql).setFirstResult(page).setMaxResults(pagesize).list();
		
	}

	@Override
	public void addMaterielInfomation(MaterielInformation materielInfomation) {
		this.getHibernateTemplate().save(materielInfomation);
	}

	@Override
	public void updateMaterielInfomation(MaterielInformation materielInfomation) {
		this.getHibernateTemplate().update(materielInfomation);
	}

	@Override
	public void deleteMaterielInfomation(MaterielInformation materielInfomation) {
		this.getHibernateTemplate().delete(materielInfomation);
	}

	@Override
	public MaterielInformation getMaterielInfomationById(Long id) {
		MaterielInformation m = (MaterielInformation)this.getHibernateTemplate().load(MaterielInformation.class, id);
		return m;
	}

	@Override
	public MaterielInformation getMaterielInfomationByMaterialNo(
			String materialNo) {
		MaterielInformation m = (MaterielInformation)this.getSession().createQuery("from MaterielInformation m where m.materielNO = ?").setString(0, materialNo).uniqueResult();
		return m;
	}

	@Override
	public long countMaterielInfomation(String sql) {
		long m = (Long)this.getSession().createQuery(sql).uniqueResult();
		return m;
	}

}
